package antlr.arrayInitTest;

import antlr.arrayInitGen.ArrayInitLexer;
import antlr.arrayInitGen.ArrayInitParser;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

public class ArrayInitDemo {
    public static void main(String[] args) {
        //定义输入数据
        String line = "{1,2,3}";

        //1.Lexical analysis
        ArrayInitLexer lexer = new ArrayInitLexer(new ANTLRInputStream(line));
        CommonTokenStream tokens = new CommonTokenStream(lexer);

        //2.Syntax analysis
        ArrayInitParser parser = new ArrayInitParser(tokens);
        ParseTree  tree = parser.init();

        //3.Application based on Syntax Tree
        ParseTreeWalker walker = new ParseTreeWalker();
        walker.walk(new ShortToUnicodeString(),tree);

        System.out.println();
    }
}